﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WebUI.BL.ProductColorBL;
using WebUI.BL.Products;
using WebUI.Models;

namespace WebUI.AdminSite.Product
{
    public partial class ProductColor : System.Web.UI.Page
    {
        public string page="";
        public int idPage=0;
        protected void Page_Load(object sender, EventArgs e)
        {
            page = Request.QueryString["Page"] == null ? "1" : Request.QueryString["Page"];
            int.TryParse(page, out idPage);
            if (!IsPostBack)
            {
                BindData(this.idPage);
            }
            
        }

        private  void DisplayUcPage()
        {
            
        }

        private void BindData(int idPage=0)
        {
            var repository = new ProductColorBL();

            int pageSize = 2;
            int countProductColor = repository.CountProductColor();
            int howManyPage = (int)Math.Ceiling((decimal) countProductColor/(decimal) pageSize);

            var pagingInfo = new PagingInfo
            {
                CurrentPage = String.IsNullOrEmpty(page) ? 1 : idPage,
                PageUrlLink = "ProductColor.aspx",
                HowManyPage = howManyPage,
                Pagesize = pageSize,
                TotalItem = countProductColor
            };

            UCPager1.DisplayPager(pagingInfo,(pagelink,curp)=>(Helpers.link.ToAdminProductColor(pagelink,curp)));

            string fromdate = txtDatePickerFrom.Text;
            string todate = txtDatePickerTo.Text;
 
            
            /*Son demo delegate tra ve Anymous Type*/
            int index = 1;
            //var dataS =
                //repository.GetProductColors1((a, b, c, d, e, f, g, h) => new Models.MODEL_SP_ADMIN_SEARCH_ProductColor
                //                                                             {
                //                                                                 STT = index++,
                //                                                                 ColorCode = a.ToString(),
                //                                                                 ColorName = b.ToString(),
                //                                                                 ColorDesc = c.ToString(),
                //                                                                 ColorNo = d.ToString(),
                //                                                                 CreateDate = Helpers.WebFunction.FormatDateList(e),
                //                                                                 CreateUser = g.ToString(),
                //                                                                 Status = h.ToString(),
                //                                                                 Img = f.ToString(),
                                                                                 
                //                                                             }, txtColorCode.Text, txtColorName.Text, fromdate, todate, "",idPage,pageSize);
            grdColor.DataSource = null;
            //    ((ColorCode, ColorName, ColorDesc, ColorNo, CreateDate, Img, CreateUser, Status)
            //        => (new { ColorCode, ColorName, ColorDesc, ColorNo, CreateDate, Img, CreateUser, Status }),
            //txtColorCode.Text, txtColorName.Text, fromdate, todate, "");
            grdColor.DataBind();
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            BindData();
        }

       
    }
}